# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : code04.py
# @Time     : 2024/4/6 18:38
# @Author   : Robot-Zsj
"""
description:

input
2 2
1 0
1 1

output
3
"""


def main():
    n, m = map(int, input().split())
    matrix = [list(map(int, input().split())) for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(m):
            if matrix[i][j] == 1:
                ans = max(ans, bfs(i, j, matrix, n, m))
    return ans


directions = ((1, 0), (0, 1), (-1, 0), (0, -1))


def bfs(i, j, matrix, n, m):
    count = 1
    matrix[i][j] = 0
    queue = [[i, j]]
    while len(queue) > 0:
        x, y = queue.pop(0)
        for dirx, diry in directions:
            newX = x + dirx
            newY = y + diry
            if n > newX >= 0 and m > newY >= 0 and matrix[newX][newY] == 1:
                count += 1
                matrix[newX][newY] = 0
                queue.append([newX, newY])
    return count


print(main())
